using System;
using FytSoa.CrossCutting.Middleware.Filter;
using Microsoft.AspNetCore.Builder;
using FytSoa.Common.Utils;

namespace FytSoa.CrossCutting.Middleware
{
    public static class MiddlewareConfig
    {
        public static void UseMiddlewareSetup (this IApplicationBuilder app) {
            if (app == null) throw new ArgumentNullException (nameof (app));

            //DI
            ServiceLocator.Instance = app.ApplicationServices;

            // global error
            app.UseMiddleware<ExceptionFilter> ();

            // check jwt token
            app.UseMiddleware<JwtTokenFilter> ();

            // authentication
            app.UseAuthentication ();
        }
    }
}